package WW;





import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

public class W5 extends JFrame implements ActionListener{

	public static void main(String[] args) {
		W5 a=new W5();
		 	    
	}
	    JFrame j;
	    JPanel p;
	    int a,b;
	    int ai,bj;
	    JButton[][] btn =new JButton[9][9];
	public W5() {
		
		a = (int)(Math.random()*100%9);
		b = (int)(Math.random()*100%9);
		System.out.println(""+a+b);
		j = new JFrame("");
		j.setBounds(1300, 500, 600, 600);
		p = new JPanel(new GridLayout(9,9));
		
		for(int i = 0 ;i<9;i++) {
			for(int j =0;j<9;j++) {
				btn[i][j] = new JButton();
				p.add(btn[i][j]);
				btn[i][j].addActionListener(this);
			}
	}
		j.add(p);
		j.setVisible(true);
}
	public void actionPerformed(ActionEvent e) {
		if(e.getSource()==	btn[a][b]) {
			JOptionPane.showMessageDialog(null, "Bingo");
			btn[a][b].setBackground(Color.GREEN);
		}else {
			for(int i = 0 ;i<9;i++) {
				for(int j =0;j<9;j++) {
					if(e.getSource()==btn[i][j] &&e.getSource() !=	btn[a][b]) {
						btn[i][j].setBackground(Color.PINK);
						ai = i - a;
						bj = j - b;
						if(ai<0) {ai = -ai;}
						if(bj<0) {bj = -bj;}
						btn[i][j].setText(""+(ai+bj));
					}
				}
			}
		}
		
	}
}